<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 400px;
            height: 200px;
            border: 1px solid black;
            text-align: center;
            margin-top: 200px;
            margin-left: 200px;
            border-radius: 10px;
        }

        .box input {
            width: 150px;
            height: 30px;
            font-size: 14px;
            margin: 5px;
            border-radius: 10px;
        }

        .box .in1 {
            margin-top: 30px;
        }

        .box .mima {
            font-size: 12px;
            margin-left: 105px;
            color: blue;
        }
    </style>
</head>

<body>
    <div class="box">
        <input type="text" placeholder="手机号/用户名/邮箱" class="in1">
        <br>
        <input type="password" placeholder="密码">
        <div class="mima">忘记密码</div>
        <input type="button" value="登录">
    </div>
</body>

</html>
<script src="./promise封装ajax.js"></script>
<script>
    var ins = document.querySelectorAll('.box input')
    ins[2].onclick = function () {
        if (ins[0].value && ins[1].value) {
            if ((/^\d{4}$/.test(ins[1].value)) && (/^\d{4}$/.test(ins[1].value))) {
                ajax('get', 'https://yantianfeng.com/api/login', { username: ins[0].value, password: ins[1].value }).then((data) => {
                    alert(data.msg)
                })
            } else {
                alert('请输入正确的账号密码')
            }
        } else {
            alert('账号密码不能为空')
        }
    } 
</script>